<?php
//amops file
if(!checkQualified("1000")) {
	print "You are not allowed to perform this action! (You=" . $_SESSION[permission] . " : Req'd=1000)";
}  else {
	
	
	switch($_REQUEST['op']) {
		case 'newEmp':
			?>
			<div style="margin:auto; text-align:center; ">
				<p style="text-align:center; ">Add New Employee</p>
				<?php
					if(isset($_REQUEST['netID'])) {
						$sql = sprintf("INSERT INTO `t_drivers` (`lastname`,`firstname`,`netid`) VALUES ( %s , %s , %s )",
										quote_smart($_REQUEST['lastName']),
										quote_smart($_REQUEST['firstName']),
										quote_smart($_REQUEST['netID']));
						$result = mysql_query($sql);
						if(mysql_affected_rows() == 1) {
							$newDriverId = mysql_insert_id();
							$statusMsg = 'Driver ' . $_REQUEST['netID'] . ' was successfully added.<BR>' . "\n<a href='" . $_SERVER['PHP_SELF'] . "?op=editEmp&amp;driver_id=" . $newDriverId . "'>Click here</a> to edit this employee.";
						} else {
							$statusMsg = "<span style='color: red; font-weight: bold;'>An error occurred!</span><br>" . mysql_error();
						}
						?>
						<div style="border: 1px solid #000000; "><?= $statusMsg ?></div>
						<?php
					}
				?>
				<form action="<?= $_SERVER['PHP_SELF'] ?>?op=newEmp" method="post">
				<table>
					<tr>
						<td>First Name</td>
						<td><input type="text" name="firstName"></td>
					</tr>
					<tr>
						<td>Last Name</td>
						<td><input type="text" name="lastName"></td>
					</tr>
					<tr>
						<td>NetID</td>
						<td><input type="text" name="netID"></td>
					</tr>
					<tr>
						<td colspan="2"><input type="submit" value="Add New Employee"></td>
					</tr>
				</table>
				</form>
			</div>
			<?php
			
			break;
		case 'modifyPoints':
	?>
<div style="text-align:center; "><h1>Modify Seniority Points</h1></div>
<div id="ajaxStatus" style="height:20px; font-weight:bold; text-align:center; "></div>
<table style="width: 350px; margin:auto;">
  <tr>
    <td>Driver </td>
    <td><select name="select" style="width: 200px; " id="seniority_driver">
			<option value="" selected> - Select an Employee - </option>
			<?php
				$driver_sql = "SELECT `driver_id` , concat( `lastname` , \", \", `firstname` ) AS name FROM t_drivers WHERE `terminated` IS NULL ORDER BY `lastname` ASC, `firstname` ASC";
				$driver = mysql_query($driver_sql);
				while($driver_data = mysql_fetch_assoc($driver)) {
					print "    <option value=\"" . $driver_data['driver_id'] . "\">" . $driver_data['name'] . "</option>\n";
				}
				mysql_free_result($driver);
			?>
    </select></td>
  </tr>
  <tr>
    <td>Points </td>
	<td><input name="text" id="seniority_points" type="text" style="width:75px;" /></td>

  </tr>
  <tr>
    <td>Reason for Adjustment:</td>
    <td ><textarea style="width: 200px; " id="seniority_reason"></textarea></td>
  </tr>
  <tr>
  </tr>
  <tr>
    <td colspan="2" style="text-align:center; "><input type="checkbox" id="clearFields" value="1" > 
    On save, reset fields</td>
  </tr>
  <tr>
    <td colspan="2" style="text-align:center; "><input type="button" id="saveButton" value="Save" onclick="addPoints()"></td>
  </tr>
  <tr>
    <td colspan="2" style="text-align:center; ">Previous Points Posted (This session)<br><select multiple size="10" style="width:350px; " id="seniority_completed"></select></td>
  </tr>
</table>
	<?php
			
			break;
		case 'promote':
	?>
	<div style="text-align:center; margin:5px; "><h1>Employee Promotions</h1></div>
	<div style="text-align:center; margin:5px; ">
		<form name="jumpDriver">
		  <select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
			<option value="" selected> - Select an Employee - </option>
			<?php
				$driver_sql = "SELECT `driver_id` , concat( `lastname` , \", \", `firstname` ) AS name FROM t_drivers WHERE `terminated` IS NULL ORDER BY `lastname` ASC, `firstname` ASC";
				$driver = mysql_query($driver_sql);
				while($driver_data = mysql_fetch_assoc($driver)) {
					print "    <option value=\"?op=promote&amp;driver_id=" . $driver_data['driver_id'] . "\">" . $driver_data['name'] . "</option>\n";
				}
				mysql_free_result($driver);
			?>
		  </select>
		</form>
	</div>	
	<?php	
			if($_REQUEST['process']) { //process promotion
				$new_permission = $_REQUEST['checkbox1'] + $_REQUEST['checkbox2'] + $_REQUEST['checkbox3'] + $_REQUEST['checkbox4'] + $_REQUEST['checkbox5'] + $_REQUEST['checkbox6'] + $_REQUEST['checkbox7'] + $_REQUEST['checkbox8'] + $_REQUEST['checkbox9'];			
				$sql = "UPDATE `t_drivers` SET `permission` = $new_permission WHERE `driver_id` = " . $_REQUEST['driver_id'] . " LIMIT 1";
				$update = mysql_query($sql);
				if(mysql_affected_rows() == 1) {
					print "Permissions saved for " . $_REQUEST['driver_name'] . " as $new_permission.";
				} else {
					print "An error occurred while trying to save your permission data.";
				}
			} else { //allow to promote
				if(isset($_REQUEST['driver_id'])) {
					$driver_sql = "SELECT * FROM t_drivers WHERE `driver_id` = " . $_REQUEST['driver_id'];
					$driver = mysql_query($driver_sql);
					$driver_info = mysql_fetch_assoc($driver);
					?>
	<div style="text-align:center; margin:5px;"><h2><?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?></h2></div>
	<form action="index.php" method="get">
	<input type="hidden" name="driver_id" value="<?= $driver_info['driver_id'] ?>">
	<input type="hidden" name="process" value="1">
	<input type="hidden" name="op" value="promote">
	<input type="hidden" name="driver_name" value="<?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?>">
	<div style="text-align:center; margin:5px; ">
	<table border="0" cellspacing="2" cellpadding="0" style="margin:auto; ">
		<tr>
			<td><input type="checkbox" name="checkbox1" value="1000" <?php if(checkQualified('1000',$driver_info['permission'])) { print "checked"; } ?>></td>
			<td>Coordinator</td>
			<td><input type="checkbox" name="checkbox2" value="100" <?php if(checkQualified('0100',$driver_info['permission'])) { print "checked"; } ?>></td>
			<td>PM</td>
			<td><input type="checkbox" name="checkbox3" value="4" <?php if(checkQualified('0004',$driver_info['permission'])) { print "checked"; } ?>></td>
			<td>Shuttle Driver </td>
		</tr>
		<tr>
			<td><input type="checkbox" name="checkbox4" value="400" <?php if(checkQualified('0400',$driver_info['permission'])) { print "checked"; } ?>></td>
			<td>Dispatcher</td>
			<td><input type="checkbox" name="checkbox5" value="10" <?php if(checkQualified('0010',$driver_info['permission'])) { print "checked"; } ?>></td>
			<td>Storrs/Mansfield</td>
			<td><input type="checkbox" name="checkbox6" value="2" <?php if(checkQualified('0002',$driver_info['permission'])) { print "checked"; } ?>></td>
			<td>Bus Wash </td>
		</tr>
		<tr>
			<td><input type="checkbox" name="checkbox7" value="200" <?php if(checkQualified('0200',$driver_info['permission'])) { print "checked"; } ?>></td>
			<td>Trainer</td>
			<td><input type="checkbox" name="checkbox8" value="20" <?php if(checkQualified('0020',$driver_info['permission'])) { print "checked"; } ?>></td>
			<td>Buckland</td>
			<td><input type="checkbox" name="checkbox9" value="1" <?php if(checkQualified('0001',$driver_info['permission'])) { print "checked"; } ?>></td>
			<td>Trainee</td>
		</tr>
	</table>
	</div>
	<div style="text-align:center; margin:5px;"><input type="submit" name="Submit" value="Save Permissions"></div>
	</form>
					<?php
				}
			}
		
		break;
		case 'terminate':
	
	?>
	<div style="text-align:center; ">
		<h1>Terminate/Reactivate Employees</h1>
	
	<?php
			if($_REQUEST['process']) { //process promotion
				if($_REQUEST['activate']) {
					$sql = "UPDATE `t_drivers` SET `terminated` = null, `active` = 1, `allow_login` = 1, `signups_active` = 1 WHERE `driver_id` = " . $_REQUEST['driver_id'];
					$update = mysql_query($sql);
					if(mysql_affected_rows() == 1) {
						print "<p>Employment status for " . $_REQUEST['driver_name'] . " set as Active.</p>";
					} else {
						print "<p>An error occurred while trying to change " . $_REQUEST['driver_name'] ."'s employment status.</p>";
					}
				} else if ($_REQUEST['terminate']) {
				
					$terminate_year = date("Y");
					$sql = "UPDATE `t_drivers` SET `terminated` = $terminate_year, `active` = 0, `allow_login` = 0, `signups_active` = 0 WHERE `driver_id` = " . $_REQUEST['driver_id'] . " LIMIT 1";
					$update = mysql_query($sql);
					if(mysql_affected_rows() == 1) {
						print "<p>Employment status for " . $_REQUEST['driver_name'] . " set as Terminated.</p>";
					} else {
						print "<p>An error occurred while trying to change " . $_REQUEST['driver_name'] ."'s employment status.</p>";
					}
				}
			} 
	?>

		<form name="jumpDriver">
		<table style="margin:auto; ">
			<tr>
				<td style="font-weight:bold; ">Active Employees</td>
				<td style="font-weight:bold; ">Terminated Employees</td>
			</tr>
			<tr>
				<td>	
	  <select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
		<option value="" selected> - Select an Employee - </option>
		<?php
			$driver_sql = "SELECT `driver_id` , concat( `lastname` , \", \", `firstname` ) AS name FROM t_drivers WHERE `terminated` IS NULL ORDER BY `lastname` ASC, `firstname` ASC";
			$driver = mysql_query($driver_sql);
			while($driver_data = mysql_fetch_assoc($driver)) {
				print "    <option value=\"?op=terminate&amp;driver_id=" . $driver_data['driver_id'] . "\">" . $driver_data['name'] . "</option>\n";
			}
			mysql_free_result($driver);
		?>
	  </select></td>
				<td>	
	  <select name="menu2" onChange="MM_jumpMenu('parent',this,0)">
		<option value="" selected> - Select an Employee - </option>
		<?php
			$driver_sql = "SELECT `driver_id` , concat( `lastname` , \", \", `firstname` ) AS name FROM t_drivers WHERE `terminated` IS NOT NULL ORDER BY `lastname` ASC, `firstname` ASC";
			$driver = mysql_query($driver_sql);
			while($driver_data = mysql_fetch_assoc($driver)) {
				print "    <option value=\"?op=terminate&amp;driver_id=" . $driver_data['driver_id'] . "\">" . $driver_data['name'] . "</option>\n";
			}
			mysql_free_result($driver);
		?>
	  </select>
	
</td>
			</tr>
		</table>
		</form>
	<p>&nbsp;</p>
	<div style="width: 400px; margin:auto; text-align:center; ">
	<?php	
			if($_REQUEST['process']) { //this part is deprecated
			} else { //allow to terminate/activate
				if(isset($_REQUEST['driver_id'])) {
					$driver_sql = "SELECT * FROM t_drivers WHERE `driver_id` = " . $_REQUEST['driver_id'];
					$driver = mysql_query($driver_sql);
					$driver_info = mysql_fetch_assoc($driver);
					?>
					<p><h2><?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?></h2></p>
					<form action="index.php" method="get">
					<input type="hidden" name="driver_id" value="<?= $driver_info['driver_id'] ?>">
					<input type="hidden" name="process" value="1">
					<input type="hidden" name="op" value="terminate">
					<input type="hidden" name="driver_name" value="<?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?>">
					<?php
					if($driver_info['terminated'] > 1) {
						//this person is currently terminated
					?>
					<p style="text-align:left; "><?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?> was terminated in the system in <?= $driver_info['terminated'] ?>. If you would like to reactivate him/her within this system, check the box below, and click the Update button.</p>
					<p><input type="checkbox" name="activate" value="1"> Reactivate Employee</p>
					<?php
					} else {
						//this person is currently employed in the system
					?>
					<p style="text-align:left; "><?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?> is currently active in the system. If you would like to terminate him/her within this system, check the box below, and click the Update button.</p>
					<p><input type="checkbox" name="terminate" value="1"> Terminate Employee</p>
					<?php
					}
					?>
					<p><input type="submit" name="Submit" value="Update Employment Status"></p>
					</form>
					<?php
				}
			}
		?></div>	</div>
<?php
		break;
		case 'schedStatus':
	
	?>
	<div style="text-align:center; ">
		<h1>Change Schedule Status</h1>
	<div style="width: 400px; margin:auto; text-align:center; ">
		<p style="text-align:left; ">From here, you can change the status of any schedule within the system. Keep in mind that a schedule in `Archive` mode will not appear anywhere else on the site!</p>
		<p style="text-align:left; ">Schedules are listed in descending order from time used.</p>
		<?php
			if(isset($_REQUEST['group'])) {
				//they are trying to change a schedule.. lets update it..
				$sql = sprintf("UPDATE `t_sched_groups` SET `status` = %s WHERE `group_id` = %s LIMIT 1",quote_smart($_REQUEST['status']),quote_smart($_REQUEST['group']));
				$update = mysql_query($sql);
				if(mysql_affected_rows() == 1) {
					alertText("Your schedule change was successful!");
				} else {
					errorText("An error occurred trying to make your schedule change.");
				}
			}
		?>
	<table style="margin:auto; width:390px;">		
		<?php
			$group_sql = "SELECT * FROM t_sched_groups ORDER BY `year_used` DESC, `group_id` DESC";
			$group = mysql_query($group_sql);
			$year = 0;
			while($group_data = mysql_fetch_assoc($group)) {
				if($year != $group_data['year_used']) {
					$year = $group_data['year_used'];
					?>
		<tr height="40">
			<td colspan="5" style="text-align:left; border-bottom: 2px solid black; padding-top:10px; vertical-align:bottom;"><h2><?= $year ?></h2></td>
		</tr>
					<?php
				}
		?>
		<tr height="30">
			<td></td>
			<td colspan=4 style="text-align:left; font-weight:bold; vertical-align:bottom; "><?= $group_data['description'] ?></td>
		</tr>
		<tr>
			<td></td>
			<td style="vertical-align:middle; "><?php if($group_data['status'] == -1) { ?><span style="font-weight:bold; ">Archived</span><?php } else { ?><a href="?op=schedStatus&amp;group=<?=$group_data['group_id']?>&amp;status=-1"><?= displayIcon(ICON_SCHED_ARCHIVE) ?> Archive</a><?php  } ?></td>
			<td style="vertical-align:middle; "><?php if($group_data['status'] == 0 ) { ?><span style="font-weight:bold; ">Closed</span><?php   } else { ?><a href="?op=schedStatus&amp;group=<?=$group_data['group_id']?>&amp;status=0"><?= displayIcon(ICON_SCHED_CLOSE)   ?> Close</a><?php    } ?></td>
			<td style="vertical-align:middle; "><?php if($group_data['status'] == 1 ) { ?><span style="font-weight:bold; ">Pending</span><?php  } else { ?><a href="?op=schedStatus&amp;group=<?=$group_data['group_id']?>&amp;status=1"><?= displayIcon(ICON_SCHED_PENDING) ?> Pending</a><?php  } ?></td>
			<td style="vertical-align:middle; "><?php if($group_data['status'] == 2 ) { ?><span style="font-weight:bold; ">Schedule</span><?php } else { ?><a href="?op=schedStatus&amp;group=<?=$group_data['group_id']?>&amp;status=2"><?= displayIcon(ICON_SCHED_SCHEDULE)?> Schedule</a><?php } ?></td>
		</tr>
		<?php
			}
			mysql_free_result($group);
		?>
	</table>
	</div>
	<?php /*
			if($_REQUEST['process']) { //process promotion
				if($_REQUEST['activate']) {
					$sql = "UPDATE `t_drivers` SET `terminated` = null, `active` = 1, `allow_login` = 1, `signups_active` = 1 WHERE `driver_id` = " . $_REQUEST['driver_id'];
					$update = mysql_query($sql);
					if(mysql_affected_rows() == 1) {
						print "<p>Employment status for " . $_REQUEST['driver_name'] . " set as Active.</p>";
					} else {
						print "<p>An error occurred while trying to change " . $_REQUEST['driver_name'] ."'s employment status.</p>";
					}
				} else if ($_REQUEST['terminate']) {
				
					$terminate_year = date("Y");
					$sql = "UPDATE `t_drivers` SET `terminated` = $terminate_year, `active` = 0, `allow_login` = 0, `signups_active` = 0 WHERE `driver_id` = " . $_REQUEST['driver_id'] . " LIMIT 1";
					$update = mysql_query($sql);
					if(mysql_affected_rows() == 1) {
						print "<p>Employment status for " . $_REQUEST['driver_name'] . " set as Terminated.</p>";
					} else {
						print "<p>An error occurred while trying to change " . $_REQUEST['driver_name'] ."'s employment status.</p>";
					}
				}
			} 
	?>

		<form name="jumpDriver">
		<table style="margin:auto; ">
			<tr>
				<td style="font-weight:bold; ">Active Employees</td>
				<td style="font-weight:bold; ">Terminated Employees</td>
			</tr>
			<tr>
				<td>	
	  <select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
		<option value="" selected> - Select an Employee - </option>
		<?php
			$driver_sql = "SELECT `driver_id` , concat( `lastname` , \", \", `firstname` ) AS name FROM t_drivers WHERE `terminated` IS NULL ORDER BY `lastname` ASC, `firstname` ASC";
			$driver = mysql_query($driver_sql);
			while($driver_data = mysql_fetch_assoc($driver)) {
				print "    <option value=\"?op=terminate&amp;driver_id=" . $driver_data['driver_id'] . "\">" . $driver_data['name'] . "</option>\n";
			}
			mysql_free_result($driver);
		?>
	  </select></td>
				<td>	
	  <select name="menu2" onChange="MM_jumpMenu('parent',this,0)">
		<option value="" selected> - Select an Employee - </option>
		<?php
			$driver_sql = "SELECT `driver_id` , concat( `lastname` , \", \", `firstname` ) AS name FROM t_drivers WHERE `terminated` IS NOT NULL ORDER BY `lastname` ASC, `firstname` ASC";
			$driver = mysql_query($driver_sql);
			while($driver_data = mysql_fetch_assoc($driver)) {
				print "    <option value=\"?op=terminate&amp;driver_id=" . $driver_data['driver_id'] . "\">" . $driver_data['name'] . "</option>\n";
			}
			mysql_free_result($driver);
		?>
	  </select>
	
</td>
			</tr>
		</table>
		</form>
	<p>&nbsp;</p>
	<div style="width: 400px; margin:auto; text-align:center; ">
	<?php	
			if($_REQUEST['process']) { //this part is deprecated
			} else { //allow to terminate/activate
				if(isset($_REQUEST['driver_id'])) {
					$driver_sql = "SELECT * FROM t_drivers WHERE `driver_id` = " . $_REQUEST['driver_id'];
					$driver = mysql_query($driver_sql);
					$driver_info = mysql_fetch_assoc($driver);
					?>
					<p><h2><?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?></h2></p>
					<form action="index.php" method="get">
					<input type="hidden" name="driver_id" value="<?= $driver_info['driver_id'] ?>">
					<input type="hidden" name="process" value="1">
					<input type="hidden" name="op" value="terminate">
					<input type="hidden" name="driver_name" value="<?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?>">
					<?php
					if($driver_info['terminated'] > 1) {
						//this person is currently terminated
					?>
					<p style="text-align:left; "><?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?> was terminated in the system in <?= $driver_info['terminated'] ?>. If you would like to reactivate him/her within this system, check the box below, and click the Update button.</p>
					<p><input type="checkbox" name="activate" value="1"> Reactivate Employee</p>
					<?php
					} else {
						//this person is currently employed in the system
					?>
					<p style="text-align:left; "><?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?> is currently active in the system. If you would like to terminate him/her within this system, check the box below, and click the Update button.</p>
					<p><input type="checkbox" name="terminate" value="1"> Terminate Employee</p>
					<?php
					}
					?>
					<p><input type="submit" name="Submit" value="Update Employment Status"></p>
					</form>
					<?php
				}
			}
		?></div>	</div>
<?php  */
		break;
		case 'editEmp':
	?>
	<div style="text-align:center; margin:5px;"><h1>Edit Employee Data</h1></div>
	<div style="text-align:center; margin:5px;">
		<form name="jumpDriver">
		  <select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
			<option value="" selected> - Select an Employee - </option>
			<?php
				$driver_sql = "SELECT `driver_id` , concat( `lastname` , \", \", `firstname` ) AS name FROM t_drivers WHERE `terminated` IS NULL ORDER BY `lastname` ASC, `firstname` ASC";
				$driver = mysql_query($driver_sql);
				while($driver_data = mysql_fetch_assoc($driver)) {
					print "    <option value=\"?op=editEmp&amp;driver_id=" . $driver_data['driver_id'] . "\">" . $driver_data['name'] . "</option>\n";
				}
				mysql_free_result($driver);
			?>
		  </select>
		</form>
	</div>
	
	<?php	
			if($_SERVER['REQUEST_METHOD'] == 'POST') { 
				if($_REQUEST['signups_active'] != 1) {
					$signupsactive=0;
				} else {
					$signupsactive=1;
				}
				if($_REQUEST['allow_login'] != 1) {
					$allowlogin=0;
				} else {
					$allowlogin=1;
				}
				if($_REQUEST['eligible'] != 1) {
					$eligible=0;
				} else {
					$eligible=1;
				}
				if($_REQUEST['durational'] != 1) {
					$durational=0;
				} else {
					$durational=1;
				}
				$sql = "UPDATE `t_drivers` SET `eligible` = $eligible, `email` = " . quote_smart($_REQUEST['email']) . ", `durational` = $durational, `allow_login` = $allowlogin, `signups_active` = $signupsactive WHERE `driver_id` = " . $_REQUEST['driver_id'] . " LIMIT 1";
				$update = mysql_query($sql);
				if(mysql_affected_rows() == 1) {
					print "Permissions saved for " . $_REQUEST['driver_name'] . " as $new_permission.";
				} else {
					print "An error occurred while trying to save your permission data.";
				}
			} else { //allow to promote
				if(isset($_REQUEST['driver_id'])) {
					$driver_sql = "SELECT * FROM t_drivers WHERE `driver_id` = " . $_REQUEST['driver_id'];
					$driver = mysql_query($driver_sql);
					$driver_info = mysql_fetch_assoc($driver);
					?>
					<div align="left"><h2><?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?></h2></div>
	<form action="index.php" method="post">
	<input type="hidden" name="driver_id" value="<?= $driver_info['driver_id'] ?>">
	<input type="hidden" name="op" value="editEmp">
	<input type="hidden" name="driver_name" value="<?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?>">
	<table border="0" cellspacing="2" cellpadding="0" border=1>
	  <tr>
		<td><input type="checkbox" name="signups_active" value="1" <?php if($driver_info['signups_active']) { print "checked"; } ?>></td>
		<td>Signups Active</td>
	  </tr>
	  <tr>
		<td><input type="checkbox" name="eligible" value="1" <?php if($driver_info['eligible']) { print "checked"; } ?>></td>
		<td>Eligible to use system</td>
	  </tr>
	  <tr>
		<td><input type="checkbox" name="durational" value="1" <?php if($driver_info['durational']) { print "checked"; } ?>></td>
		<td>Durational</td>
	  </tr>
	  <tr>
		<td><input type="checkbox" name="allow_login" value="1" <?php if($driver_info['allow_login']) { print "checked"; } ?>></td>
		<td>Allow Login</td>
	  </tr>
	  <tr>
		<td>Email Address:</td>
		<td><input type="text" name="email" value="<?= $driver_info['email'] ?>"></td>
	  </tr>
	  <tr>
		<td colspan="6" align="center"><input type="submit" name="Submit" value="Save Permissions"></td>
	  </tr>
	</table>
	</form>
					<?php
				}
			}
		
		break;
		case 'editDurationals':
	?>
	<div style="text-align:center; margin:5px;"><h1>Edit Durational Logins</h1></div>
	<div style="text-align:center; margin:5px;">
		<form name="jumpDriver">
		  <select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
			<option value="" selected> - Select a Durational - </option>
			<?php
				$driver_sql = "SELECT `driver_id` , concat( `lastname` , \", \", `firstname` ) AS name FROM t_drivers WHERE `terminated` IS NULL AND `durational` = 1 ORDER BY `lastname` ASC, `firstname` ASC";
				$driver = mysql_query($driver_sql);
				while($driver_data = mysql_fetch_assoc($driver)) {
					print "    <option value=\"?op=editDurationals&amp;driver_id=" . $driver_data['driver_id'] . "\">" . $driver_data['name'] . "</option>\n";
				}
				mysql_free_result($driver);
			?>
		  </select>
		</form>
	</div>
	
	<?php	
			if($_SERVER['REQUEST_METHOD'] == 'POST') { //process promotion
				$driver_sql = "SELECT * FROM t_drivers WHERE `driver_id` = " . $_REQUEST['driver_id'];
				$driver = mysql_query($driver_sql);
				$driver_info = mysql_fetch_assoc($driver);
				$passAddin = "";
				$username = $_REQUEST['username'];
				if($_REQUEST['pass_reset']) {
					$newPass = generatePassword();
					$passAddin = ", `password` = '" . crypt($newPass,substr($newPass,0,2)) . "' ";
					print $passAddin;
				}
				$sql = "UPDATE `t_drivers` SET `netid` = " . quote_smart($username) . $passAddin . " WHERE `driver_id` = " . $_REQUEST['driver_id'] . " LIMIT 1";
				$update = mysql_query($sql);
				if(mysql_affected_rows() == 1) {
					print "Durational login data saved for " . $_REQUEST['driver_name'] . ".";
					if($_REQUEST['pass_reset']) {
						//try to reset password
						if(empty($_REQUEST['username'])) {
							print " The password couldn't be reset though because there is no username.";
						} else {
							if(mail($driver_info['email'],"Transpo Password Reset","Your password for the UConn Transpo website has been reset.\n\nUsername: " . $username . "\nPassword: $newPass","From: transpo@park.uconn.edu")) {
								print " Password reset was successful.";
							} else {
								print " Password reset was successful but we couldn't email it. The password was set to  " . $newPass;
							}
						}
					}
				} else {
					print "An error occurred while trying to save your permission data.";
				}
			} else { //allow to promote
				if(isset($_REQUEST['driver_id'])) {
					$driver_sql = "SELECT * FROM t_drivers WHERE `driver_id` = " . $_REQUEST['driver_id'];
					$driver = mysql_query($driver_sql);
					$driver_info = mysql_fetch_assoc($driver);
					?>
					<div style="text-align:center;"><h2><?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?></h2></div>
	<form action="index.php" method="post">
	<input type="hidden" name="driver_id" value="<?= $driver_info['driver_id'] ?>">
	<input type="hidden" name="op" value="editDurationals">
	<input type="hidden" name="driver_name" value="<?= $driver_info['firstname'] ?> <?= $driver_info['lastname'] ?>">
	<table border="0" style="margin:auto; " cellspacing="2" cellpadding="0" border=1>
	  <tr>
		<td>Username:</td>
		<td><input type="text" name="username" value="<?= $driver_info['netid'] ?>"></td>
	  </tr>
	  <tr>
		<td>Password Reset:</td>
		<td><?php 
			if(empty($driver_info['email'])) {
				print "Must have an email address before a password can be reset.";
			} else {
				?>
			<input type="checkbox" name="pass_reset" value="1">
				<?php
			}
			?></td>
	  </tr>
	  <tr>
		<td colspan="6" align="center"><input type="submit" name="Submit" value="Save Settings"></td>
	  </tr>
	</table>
	</form>
					<?php
				}
			}
		
		break;
		case 'editSignups':
		
			if(isset($_SESSION['editSignups'])) {


			} else {
				?>
	<div style="background-color:#D2D2FF; border: 1px solid black; text-align:center; padding: 5px; margin: 20px;">
		<form name="form1" method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
		<input type="hidden" name="sched_maker" value="1">
		Pick a group to edit: 
		<select name="group">
			<option value="0">- Create New Group -</option>
			<?php
				$sql = sprintf("SELECT * FROM `t_sched_groups` WHERE `status` > 0");
				if(DEBUG) print $sql;
				$result = mysql_query($sql);
				while($row = mysql_fetch_assoc($result)) {
			?>			
			<option value="<?= $row['group_id'] ?>"><?= $row['description'] ?></option>
			<?php
				}
				mysql_free_result($result);
			?>
		</select>
		<input type="hidden" name="level" value="group">
		<input type="submit" name="Submit" value="Go --&gt;"> 
		</form>
	</div>
				<?php
			}


		break;
		case 'viewSchedule':
		
			?>
			
			<form action="http://transpo.uconn.edu/includes/sched.php" method="post" target="_blank">
			<table border="0" cellspacing="0" cellpadding="0" align="center" style="margin: 15px; border: thin solid black; ">
			  <tr><th colspan="2">View / Print Schedule</th></tr>
			  <tr>
				<td>Schedule</td>
				<td><select name="group_id">
					<?php
			$query = mysql_query("SELECT * FROM `t_sched_groups` WHERE `status` >= 0 ORDER BY `group_id` DESC");
			while($row = mysql_fetch_assoc($query)) {
				print "<option value='" . $row['group_id'] . "'>" . $row['description'] . "</option>\n";
			}
			mysql_free_result($query);
					?>
				</select></td>
			  </tr>
			  <tr>
				<td>Image Size </td>
				<td><select name="fullsize">
					<option value="0">Regular</option>
					<option value="1">Full Size</option>
				</select></td>
			  </tr>
			  <tr>
				<td colspan="2" align="center"><input type="submit" name="Submit2" value="View Schedule"></td>
			  </tr>
			</table>
			</form>
	<?php
		break;
			case 'systemvars':
				if(!COORDINATORS_CHANGE_VARS and checkQualified("1000")) {
					alertText("Coordinators are not allowed to edit system variables.");
					return;
				}
			?>
			<h1>System Variables</h1>
			<h2>Hard-Coded:</h2>
			<div style="background-color:#FFFFFF; color:#000000; ">
				<table>
					<tr>
						<th>%SYSROOT%</th>
						<TD><?= constant("SYSROOT") ?></TD>
					</tr>
					<tr>
						<th>%ICONBASE%</th>
						<TD><?= constant("ICONBASE") ?></TD>
					</tr>
					<tr>
						<th>%INCLUDEFOLDER%</th>
						<TD><?= constant("INCLUDEFOLDER") ?></TD>
					</tr>
				</table>
			</div>
			<h2>Soft-Coded:</h2>
			<div style="background-color:#FFFFFF; color:#000000; ">
				<table>
					<?php
						$sql = "SELECT * FROM `t_sys_vars`";
						$query = mysql_query($sql);
						while($row = mysql_fetch_assoc($query)) {
						?>
					<tr>
						<th><?= $row['name']  ?></th>
						<TD><?= $row['value'] ?></TD>
					</tr>
						<?php
						}
						mysql_free_result($query);
					?>
				</table>
			</div>
			
			<?php
		break;

		case 'viewEmpShifts':
	?>
	<div style="text-align:center; margin:5px;"><h1>Employee Shifts</h1></div>
	<table style="margin-left: auto; margin-right:auto; ">
	<tr>
	<td>
	<form name="jumpDriver">
	  <select name="menu1" onChange="MM_jumpMenu('parent',this,0)" style="margin-left: auto; margin-right:auto; width:20em;">
		<?php
			if(!isset($_REQUEST['driver_id'])) print "    <option value=\"\" selected> - Select an Employee - </option>\n";
			$driver_sql = "SELECT `driver_id` , concat( `lastname` , \", \", `firstname` ) AS name FROM t_drivers WHERE `terminated` IS NULL ORDER BY `lastname` ASC, `firstname` ASC";
			$driver = mysql_query($driver_sql);
			while($driver_data = mysql_fetch_assoc($driver)) {
				if($driver_data['driver_id'] == $_REQUEST['driver_id']) {
					$selected = ' selected';
				} else {
					$selected = '';
				}
				print "    <option value=\"?op=viewEmpShifts&amp;driver_id=" . $driver_data['driver_id'] . "\"" . $selected . ">" . $driver_data['name'] . "</option>\n";
			}
			mysql_free_result($driver);
		?>
	  </select>
	</form>
	</td>
	</tr>
	</table>
	
	<?php
	if(isset($status)) $status;
	if(isset($_REQUEST['driver_id'])) {
	?>
	<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>?driver_id=<?= $_REQUEST['driver_id'] ?>&amp;task=deleteShift&amp;op=viewEmpShifts">
 	<div style="text-align:center; margin:5px;">
			<?php
			if(isset($_REQUEST['driver_id'])) {
			  $sql = sprintf('SELECT `t_sched_shifts` . * , `t_sched_structure` . * , t_sched_main.`order` AS "main_order", t_sched_main.description AS "main_desc", t_sched_groups.description AS "group_desc", t_sched_groups.status, t_sched_groups.group_id
					FROM t_sched_shifts, t_sched_structure, t_sched_main, t_sched_groups
					WHERE t_sched_shifts.driver_id = %s
					AND t_sched_shifts.table_id = t_sched_main.table_id
					AND t_sched_main.group_id = t_sched_groups.group_id
					AND t_sched_groups.status >0
					AND t_sched_shifts.structure_id = t_sched_structure.structure_id
					ORDER BY t_sched_groups.group_id DESC , t_sched_main.`order` ASC , t_sched_structure.`order` ASC
					',quote_smart($_REQUEST['driver_id']));
			  $query = mysql_query($sql);
			  printMYSQLDebug($sql,$query);
			  if($query === false)
			  	printDebug("Error with SQL query.",LVL_ERROR,"Error occurred with 'View Driver Shifts' SQL query in the AM of OPS file.",1);
			  if(mysql_num_rows($query) > 0) {
			    $guessHeight = mysql_num_rows($query) + floor(mysql_num_rows($query) / 2);
				if($guessHeight < 10) $guessHeight = 10;
				if($guessHeight > 25) $guessHeight = 25;
			  	print "		<select name=\"shift_id\" size=\"" . $guessHeight . "\" style='width:20em;'>\n";
				$thereAreShifts = true;
			  } else {
			 	$thereAreShifts = false;
				print "<p style='font-weight: bold; font-style: italic;'>There are no shifts for this driver.</p>\n";
			  }
			  while($row = mysql_fetch_assoc($query)) {
				if($row['group_desc'] != $last_group) {
					$last_group = $row['group_desc'];
					print "		<option disabled>" . $row['group_desc'] . "\n";
					$height ++;
				}
				if($row['main_desc'] != $last_main) {
					$last_main = $row['main_desc'];
					print "		<option disabled>&nbsp;&nbsp;" . $row['main_desc'] . "\n";
					$height ++;
				}
				print "		<option value='" . $row['shift_id'] . "'>&nbsp;&nbsp;&nbsp;&nbsp;" . $row['description'] . " " . $row['shift_start'] . " - " . $row['shift_end'] . "\n";
				$height ++;
				
			  }
			}
			if($thereAreShifts) 
				print "		</select>\n";
			?>
		</div>
 		<?php if($thereAreShifts) { ?>
		<div align="center" style="margin:5px; "><input type="submit" value="Delete Shift" style="width: 10 em; "></div>
		<?php } 
		
		?>
		
	<p style="text-align:center; ">Important: Only shifts from schedules set to 'Pending' or 'Schedule' will appear here.</p>
	</form>
	<?php
	}
	} // end switch
} //end checkQualified if
?>